<extend name="./base" />
<block name="body">
    <link rel="stylesheet" href="/Public/admin/order/order.css">
    <nav class="tab-btn">
        <a href="./index" class="btn ">流水单</a>
        <a href="./recharge" class="btn">充值单</a>
        <a href="./courseprice" class="btn active">课程价格</a>
    </nav>
    <table class="table">
        <thead>
        <tr>
            <th>是否认证</th>
            <th>年级</th>
            <th>家长价格</th>
            <th>老师价格</th>
            <th>修改家长价格</th>
            <th>修改老师价格</th>
        </tr>
        </thead>
        <tbody>
        <?php $is_certified_arr=array(1=>"已认证",0=>"未认证",);?>
        <?php $grade_arr = array(1=>"一年级",2=>"二年级",3=>"三年级",4=>"四年级",5=>"五年级",6=>"六年级",7=>"初一",8=>"初二",9=>"初三",10=>"高一",11=>"高二",12=>"高三",);?>
        <foreach name="lists" item="list">
            <tr>
                <td>{$is_certified_arr[$list[is_certified]]}</td>
                <td>{$grade_arr[$list[grade]]}</td>
                <td class="price">{$list.price}</td>
                <td class="teachprice">{$list.teachprice}</td>
                <td>
                    <input type="text" class="new_price" name="new_price" value="">
                    <input type="button" class="change_price" value="修改家长价格">
                    <p class="grade" style="display: none;">{$list.grade}</p>
                    <p class="is_certified" style="display: none;">{$list.is_certified}</p>
                </td>
                <td>
                    <input type="text" class="new_price" name="new_price" value="">
                    <input type="button" class="change_teachprice" value="修改家长价格">
                    <p class="grade" style="display: none;">{$list.grade}</p>
                    <p class="is_certified" style="display: none;">{$list.is_certified}</p>
                </td>
            </tr>
        </foreach>
        </tbody>
    </table>
    <div>
        {$render}
    </div>
    <script>

        function changeprice(type,_this){
            var new_price=_this.prevAll('.new_price').val();
            console.log(new_price);
            var is_certified=_this.nextAll('.is_certified').text();
            var grade=_this.nextAll('.grade').text();
            var price=_this.parents('tr').find('.price').text();
            var reg = /^(([1-9]+)|([0-9]+\.[0-9]{1,2}))$/;
            if(new_price==''||!reg.test(new_price)){
                alert("请输入需要修改的价格！")
                return false;
            }
            $.ajax({
                type:"post",
                url:"/Admin/Account/changeprice",
                dataType: 'json',
                data:{
                    is_certified:is_certified,
                    grade:grade,
                    price:new_price,
                    type:type
                },
                success:function(data){
                    if ( data.error == 0) {
                        location.reload();
                    } else{
                        alert(data.msg);
                    }
                }
            });
        }
        $('.change_price').on('click',function(){
            var _this=$(this);
            changeprice(1,_this);
        });
        $('.change_teachprice').on('click',function(){
            var _this=$(this);
            changeprice(2,_this);
        });
    </script>
</block>
